package com.liehu.user.controller;

import com.liehu.user.pojo.DetailCustomer;
import com.liehu.user.service.DetailCustomerService;
import entity.Result;
import entity.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/detailcustomer")
@CrossOrigin //跨域处理
@Api(value = "/detailcustomer",description = "客户详细信息表")
public class DetailCustomerController {
    @Autowired
    private DetailCustomerService detailCustomerService;

    /**
     * 根据客户id查询
     */
    @ApiOperation(value = "根据客户id查询", notes = "根据客户id查询")//描述
    @GetMapping("/{id}")
    public Result findByCustomerId(@PathVariable("id") String id){
        System.out.println("id:"+id);
        return  new Result(true, StatusCode.OK,"查询成功！",detailCustomerService.findByCustomerId(id));
    }

    @ApiOperation(value = "更新客户详细信息", notes = "更新客户详细信息，仅客户或管理员操作")//描述
    @PutMapping("/{id}")
    public Result update(@RequestBody DetailCustomer detailCustomer,@PathVariable("id") String id){
        detailCustomer.setId(id);
        detailCustomerService.update(detailCustomer);
        return  new Result(true, StatusCode.OK,"更新成功！");
    }

    @ApiOperation(value = "保存客户详细信息", notes = "保存客户详细信息,仅客户操作")//描述
    @PostMapping()
    public Result save(@RequestBody DetailCustomer detailCustomer){
        detailCustomerService.save(detailCustomer);
        return  new Result(true, StatusCode.OK,"保存成功！");
    }

    @ApiOperation(value = "删除客户详细信息", notes = "删除客户详细信息,仅管理员操作")//描述
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") String id){
        detailCustomerService.delete(id);
        return  new Result(true, StatusCode.OK,"删除成功！");
    }


}
